package com.chenchao.reflection;

import java.io.FileReader;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.util.Properties;

/**
 * @encoding : UTF-8
 * @Time : 2020/12/5 18:17
 * @Author : Chen Chao
 * @File : javaSE.com.chenchao.reflection.Test13.java
 * @Software : IntelliJ IDEA
 * @since : 1.8
 * 用反射配置文件执行方法
 */
public class Test13 {
    public static final String URL ="myjava01/src/com/chenchao/reflection/class.txt";
    public static void main(String[] args) {
        try {
            /*读取数据*/
            FileReader fileReader = new FileReader(URL);
            Properties properties = new Properties();
            properties.load(fileReader);
            /*加载数据*/
            Class<?> aClass = Class.forName( properties.getProperty("className"));
            Method method = aClass.getMethod( properties.getProperty("methodName"));
            Constructor<?> constructor = aClass.getConstructor();
            /*执行方法*/
            Object o = constructor.newInstance();
            method.invoke(o);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
class Student{
    public Student() {
    }
    public static void study(){
        System.out.println("天天向下！");
    }
}
class Teacher {
    public Teacher() {
    }
    public static void teach() {
        System.out.println("毁人不倦");
    }

}

